package com.ruoyi.mall.app.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.mall.app.service.DtsSearchHistoryService;
import com.ruoyi.mall.common.domain.DtsSearchHistory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/index/searchHistory")
public class DtsSearchHistoryController extends BaseController {
    @Autowired
    private DtsSearchHistoryService dtsSearchHistoryService;

    // 搜索历史记录
    @GetMapping("/searchHistoryList")
    public AjaxResult searchHistoryList(DtsSearchHistory searchHistory) {
        if (searchHistory.getUserId() == null) {
            return success(0);
        }
        return success(dtsSearchHistoryService.selectSearchHistory(searchHistory));
    }

    @GetMapping("/addSearchHistory")
    public AjaxResult addSearchHistory(DtsSearchHistory searchHistory) {
        if (searchHistory.getUserId() == null) {
            return success(0);
        }
        return success(dtsSearchHistoryService.addSearchHistory(searchHistory));
    }

    @GetMapping("/delSearchHistory")
    public AjaxResult delSearchHistory(DtsSearchHistory searchHistory) {
        if (searchHistory.getUserId() == null) {
            return success(0);
        }
        return success(dtsSearchHistoryService.delSearchHistory(searchHistory));
    }
}
